﻿using dz.u9.jky.schema.Common;
using dz.u9.jky.schema.Customer;
using dz.u9.jky.schema.Vendor;
using dz.util.core;
using Microsoft.AspNetCore.Mvc;

namespace dz.u9.webapi.Controllers
{
    /// <summary>
    /// 客户接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class CustomerController : U9BaseController
    {
        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<U9CResult> Add(DzCustomerDto customer)
        {
            customer.IsTaxPrice = true;
            if (string.IsNullOrEmpty(customer.ARConfirmTerm)) customer.ARConfirmTerm = "YZ01";
            if (string.IsNullOrEmpty(customer.RecervalTerm)) customer.RecervalTerm = "YZ01";
            if (string.IsNullOrEmpty(customer.ShippmentRule)) customer.ShippmentRule = "100";
            

            if (customer.CustomerSites == null)
            {
                DzCustomerSiteDTO site = new DzCustomerSiteDTO();
                site.Code = customer.Code;                
                site.Name = customer.Name;

                List<DzCustomerSiteDTO> sites = new List<DzCustomerSiteDTO>() { site };  

                customer.CustomerSites = sites;
            }

            return await U9Invoke(JsonUtil.Serialize(customer), new ApiParm() { Url = "DzCustomer/Add", Desc = "客户新增" });

        }

        [HttpPost]
        public async Task<U9CResult> Modify(DzCustomerDto dto)
        {
            return await U9Invoke(JsonUtil.Serialize(dto), new ApiParm() { Url = "DzCustomer/Modify", Desc = "客户修改" });           
        }
        
    }
}
